package com.bwie.redkids.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bwie.redkids.R;
import com.bwie.redkids.bean.HomeViewPagerBean.MyHomeBanner;
import com.lidroid.xutils.BitmapUtils;

public class HomePagerAdapter extends PagerAdapter {

	private ArrayList<MyHomeBanner> homeList;
	private Context context;

	public HomePagerAdapter(Context context, ArrayList<MyHomeBanner> homeList) {
		this.context = context;
		this.homeList = homeList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return Integer.MAX_VALUE;
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		// TODO Auto-generated method stub
		return arg0 == arg1;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		// super.destroyItem(container, position, object);
		container.removeView((View) object);
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		View view = View.inflate(context, R.layout.navigation_item, null);
		ImageView iv_navigation = (ImageView) view
				.findViewById(R.id.iv_navigation);
		BitmapUtils bitmapUtils = new BitmapUtils(context);
		bitmapUtils.display(iv_navigation,
				homeList.get(position % homeList.size()).getPic());
		container.addView(view);
		return view;
	}

}
